package com.base.task;

import com.base.task.em.BatchTypeEm;
import com.base.task.entity.BatchParam;
import com.base.task.entity.BatchResult;
import lombok.extern.slf4j.Slf4j;

/**
 * @ Author     ：山水之间-wxs
 * @ Description：正常数据批次
 * @ Date       ：Created in 17:52 2021/4/16
 * @ Modified By：wxs
 * @ Version    ：1.0
 */
@Slf4j
public class BatchServer extends AbstractBatchServer {

    public BatchServer(BatchParam batchParam, IBatch batchService) {
        super(batchParam, batchService);
    }

    public static BatchServer builder(IBatch batchService) {
        return builder(null, batchService);
    }

    public static BatchServer builder(BatchParam param, IBatch batchService) {
        if (param == null) {
            param = new BatchParam();
        }
        param.valid();
        return new BatchServer(param, batchService);
    }

    @Override
    protected void buildExecutor() {
        this.threadPoolExecutor = this.batchService.buildExecutor();
        if (this.threadPoolExecutor == null) {
            super.buildThreadPool();
        }
    }

    @Override
    public BatchResult runTask() {
        return super.run(BatchTypeEm.NORMAL);
    }

}
